<?php

namespace app\api\model;

class AuthImg extends Common
{
    static public function records($user_id, $to_user)
    {
        $state1 = 0;
        $imgRequest = ImgRequest::where(['user_id' => $user_id, 'to_user' => $to_user])->find();

        if ($imgRequest) {
            $endtime = strtotime($imgRequest['time']) + 15 * 24 * 3600;

            if ($endtime > time()) {
                $state1 = 1;
            }
        }

        $authImg = self::get(['user_id' => $user_id, 'to_user' => $to_user]);
        $state2 = $authImg ? 1 : 0;

        if (!$state1 && !$state2) {
            $state = 0;                       //申请和收费都没通过
        } else if ($state1 && !$state2) {
            $state = 1;                       //申请通过，收费没通过
        } else if (!$state1 && $state2) {
            $state = 2;                       //申请没通过，收费通过
        } else if ($state1 && $state2) {
            $state = 3;                       //申请和收费都通过
        }

        return $state;
    }
}
